package com.java.comprehensive.arithmetic.programmers;

import java.util.Arrays;

/**
 * @program: comprehensive-service
 *
 * @description: 判断字符是否唯一
 *
 * @author: 窦绍飞
 *
 * @create: 2021-12-17 16:07
 **/
public class OnePointZeroOne {
	public static boolean isUnique(String astr) {
		int checker = 0;
		for (int i = 0; i < astr.length(); i++) {
			int val = astr.charAt(i) - 'a';
			if ((checker & (1 << val)) > 0) {
				return false;
			}
			checker |= (1 << val);
		}
		return true;
	}

	public static boolean isUniqueTwo(String astr) {
		int[] arr = new int[128];
		for (int i = 0; i < astr.length(); i++) {
			// 把字符和数组关联
			System.out.println(astr.charAt(i));
			if (arr[astr.charAt(i)] != 0)
				return false;
			arr[astr.charAt(i)]++;
		}
		return true;
	}

	public static void main(String[] args) {
		String a = "leetcode";
		System.out.println(isUnique(a));
		int [] arr = new int [128];
		arr[a.charAt(0)]++;
		System.out.println(Arrays.toString(arr));
	}
}
